package org.lzy.shop.util

import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

object DateUtils {
    /**
     * 格式化时间为相对时间
     */
    fun formatTime(timestamp: Long): String {
        val now = System.currentTimeMillis()
        val diff = now - timestamp

        when {
            diff < 60000 -> return "刚刚"
            diff < 3600000 -> return "${diff / 60000}分钟前"
            diff < 86400000 -> return "${diff / 3600000}小时前"
            diff < 604800000 -> return "${diff / 86400000}天前"
            else -> {
                val sdf = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
                return sdf.format(Date(timestamp))
            }
        }
    }
}